<script setup>
import { ref } from 'vue'
const dialogVisible = ref(false)
const formRef = ref()

const emit = defineEmits(['success'])

const borrowerList = ref([
  { username: '10001', password: '123456789' },
  { username: '10002', password: '123456789' }
])

const adminList = ref([{ username: '20001', password: '123456789' }])

const close = async (user) => {
  dialogVisible.value = false
  emit('success', user)
}
// 组件对外暴露一个方法 open，基于open传来的参数，区分添加还是编辑
// open({})  => 表单无需渲染，说明是添加
// open({ id, cate_name, ... })  => 表单需要渲染，说明是编辑
// open调用后，可以打开弹窗
const open = () => {
  dialogVisible.value = true
}
// 向外暴露方法
defineExpose({
  open
})
</script>

<template>
  <el-dialog v-model="dialogVisible" :title="'公开账号信息'" width="30%">
    <el-form ref="formRef" label-width="100px" style="padding-right: 30px">
      <el-form-item>
        <el-collapse>
          <el-collapse-item title="借阅者账户" name="1">
            <el-button
              v-for="item in borrowerList"
              :key="item.username"
              @click="close(item)"
            >
              账号：{{ item.username }}
            </el-button>
          </el-collapse-item>
          <el-collapse-item title="图书管理员账户" name="2">
            <el-button
              v-for="item in adminList"
              :key="item.username"
              @click="close(item)"
            >
              账号：{{ item.username }}
            </el-button>
          </el-collapse-item>
        </el-collapse></el-form-item
      >
    </el-form>
    <template #footer>
      <div class="dialog-footer">
        <el-button @click="close">关闭</el-button>
      </div>
    </template>
  </el-dialog>
</template>

<style lang="scss" scoped>
.book-pic {
  width: 278px;
  height: 278px;
  display: block;
}
</style>
